/* $(document).ajaxSend(function (e, xhr, opt) {
  var user_token = localStorage.getItem("user_token");
  xhr.setRequestHeader("user_token", user_token);
}); */

$(document).ajaxSend(function (e, xhr, opt) {
  var token = localStorage.getItem("user_token");
  xhr.setRequestHeader("user_token", token);
});

function logout() {
  //删除token
  localStorage.removeItem("user_token");
  //实现页面跳转
  location.href = "blog_login.html";
}

function getUserInfo(url) {
  $.ajax({
    type: "get",
    url: url,
    success: function (result) {
      if (result.code == "SUCCESS" && result.data != null) {
        var userInfo = result.data;
        $(".left .card h3").text(userInfo.userName);
        $(".left .card a").attr("href", userInfo.githubUrl);
      } else {
        alert(result.errMsg);
      }
    },
    error: function (err) {
      if (err != null && err.status == 401) {
        location.href = "blog_login.html";
      }
    },
  });
}
